target–请求的目的地,可能是个URI或者命名调度器中的一个名称(a name from a named dispatcher).
baseRequest–jetty易变的请求对象,常常是不封装的(unwrapped).
request–请求对象,常常是封装的(wrapped).
response–响应,常常是封装的(wrapped).
The handler sets the response status, content-type and marks the request as handled before it generates the body of the response using a writer.
handler在响应以前设置响应状态、内容类型、标记请求,响应过程就是向页面写入字符“<h1>Hello World</h1>”
驱动代码如下:
publicstaticvoid main(String[] args)throwsException{
Server server =new Server(8080);
server.setHandler(new HelloHandler());
server.start();
server.join();}
Don't deploy your application in Jetty, deploy Jetty in your application.
按照以下步骤可以把jetty服务器嵌入到用户项目中:
配置Handler
jetty需要一个Handler来响应请求,Handler可能会- 检查或者修改 HTTP request.
- 产生完全的HTTP response.
- 调用其他 Handler.
- 选择一个或多个Handler来调用.
现在写一个最简单的HelloHandler,代码如下:代码中参数解析:
- target–请求的目的地,可能是个URI或者命名调度器中的一个名称(a name from a named dispatcher).
- baseRequest–jetty易变的请求对象,常常是不封装的(unwrapped).
- request–请求对象,常常是封装的(wrapped).
- response–响应,常常是封装的(wrapped).
The handler sets the response status, content-type and marks the request as handled before it generates the body of the response using a writer.handler在响应以前设置响应状态、内容类型、标记请求,响应过程就是向页面写入字符“<h1>Hello World</h1>”
驱动代码如下:
配置连接器
oo